Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
The tar npm package is used for manipulating tarballs, which are archives of files and directories. It allows users to create new tarballs, extract files from existing tarballs, and list or update the contents of tarballs. It is a JavaScript implementation of the POSIX tar command and is commonly used in Node.js applications for handling tar files.
Creating a tarball
This feature allows you to create a tarball. The example code demonstrates how to create a gzipped tarball named 'my-tarball.tgz' that contains 'file1.js' and 'file2.txt'.
const tar = require('tar');
tar.c(
{
gzip: true,
file: 'my-tarball.tgz'
},
['file1.js', 'file2.txt']
).then(_ => console.log('Tarball has been created.'));
Extracting a tarball
This feature allows you to extract files from a tarball. The example code demonstrates how to extract 'my-tarball.tgz' into the directory 'some/dir'.
const tar = require('tar');
tar.x(
{
file: 'my-tarball.tgz',
C: 'some/dir'
}
).then(_ => console.log('Tarball has been extracted.'));
Listing contents of a tarball
This feature allows you to list the contents of a tarball. The example code demonstrates how to list the paths of all files and directories in 'my-tarball.tgz'.
const tar = require('tar');
tar.t(
{
file: 'my-tarball.tgz',
onentry: entry => console.log(entry.path)
}
).then(_ => console.log('Contents have been listed.'));
Updating a tarball
This feature allows you to update a tarball by adding new files. The example code demonstrates how to add 'newfile.txt' to the existing 'my-tarball.tgz'.
const tar = require('tar');
tar.u(
{
file: 'my-tarball.tgz'
},
['newfile.txt']
).then(_ => console.log('Tarball has been updated.'));
Archiver is a streaming interface for archive generation, supporting ZIP and TAR formats. It offers more customization options for creating archives compared to tar, such as appending files from streams, buffers, or the file system with specific archive options.
Compressing is a powerful and flexible node.js compression library that supports various archive formats like tar, zip, gzip, and bzip2. It provides both streaming and promise-based APIs, which can be more convenient for certain use cases compared to tar.
Node-tar is another tarball manipulation library that can handle large files and supports streaming. It is similar to the tar package but is maintained by a different group of developers. It may have different performance characteristics or API nuances.
Tar for Node.js.
See examples/
for usage examples.
Returns an object with .Pack
, .Extract
and .Parse
methods.
Returns a through stream. Use fstream to write files into the pack stream and you will receive tar archive data from the pack stream.
This only works with directories, it does not work with individual files.
The optional properties
object are used to set properties in the tar
'Global Extended Header'.
Returns a through stream. Write tar data to the stream and the files in the tarball will be extracted onto the filesystem.
options
can be:
{
path: '/path/to/extract/tar/into',
strip: 0, // how many path segments to strip from the root when extracting
}
options
also get passed to the fstream.Writer
instance that tar
uses internally.
Returns a writable stream. Write tar data to it and it will emit
entry
events for each entry parsed from the tarball. This is used by
tar.Extract
.
FAQs
tar for node
The npm package tar receives a total of 28,979,439 weekly downloads. As such, tar popularity was classified as popular.
We found that tar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.